<div class="row-fluid">
    <?php echo $this->render('/listados/menu.phtml'); ?>

    <div class="well well-small">
        <legend>Cartas Laborales</legend>
        <form name="form_busqueda" class="form-inline noPrint" method="GET" action="<?php echo $this->baseUrl(); ?>/admin/listados/cartaslaborales">
            <div class="span12">
                <label class="control-label">Desde</label>
                <input id="desde" name="desde"   value="<?php echo empty($this->desde) ? 1 : $this->desde; ?>" class="input-mini" type="text" />
                <label class="control-label">Hasta</label>
                <input id="hasta" name="hasta"   value="<?php echo empty($this->hasta) ? 1 : $this->hasta; ?>" class="input-mini" type="text" />
                <input class="btn" value="Buscar" type="submit" />
            </div>
        </form>

        <div class="row-fluid">
            cantidad de clientes en morosidad:<?php echo ($this->cantidadDeMorosos); ?>
            <button type="button" onclick="PrintElement('#tabla_laborales')" class="btn btn-inverse noPrint" style="float: right;"><i class=" icon-print icon-white"></i>  Imprimir</button>
        </div>
        
        <div class="row-fluid " id="contenedor">
            <form action="<?php echo $this->baseUrl() ?>/admin/listados/generarcartaslaborales/" target="_blank">
                <table id="tabla_laborales" class="tabla_reducida" style="text-align: left;">
                    <thead>
                    <th></th><th></th><th></th><th>Cliente</th><th>Garante</th><th colspan="2"></th>
                    </thead>
                    <thead>
                    <th>Apellido y Nombre</th><th>Mora</th><th>Mora Original</th><th>F Otorgacion</th><th>Monto</th>
                    <th style="width:80px;" class="noPrint">
                        <input type="checkbox" id="clientes_check" onchange="MarcarCheckbox(this.id,'contenedor');" value=""></th>
                    <th style="width:80px;" class="noPrint">
                        <input type="checkbox" id="garantes_check" onchange="MarcarCheckbox(this.id,'contenedor');" value=""></th>
                    </thead>
                    <tbody>
                        <?php if (count($this->datosDeMorosos)) {
                            $i = 0;
                            ?>
                            <?php foreach ($this->datosDeMorosos as $datos) { ?>
                                <?php
                                $clienteId = $datos['cliente_id'];
                                $creditoId = $datos['credito_id'];
                                $garanteId = $datos['garante_id'];
                                ?>
                                <tr id="<?php echo "credito{$creditoId}" ?>">
                                    <td style="text-align: left;">
                                        <a href="<?php echo $this->baseUrl("usuarios/busqueda/obternerdatospersona/persona_id/{$datos['cliente_id']}") ?>" onclick="agregaMarcaUrl('<?php echo "#credito{$creditoId}" ?>')">
                                            <?php echo $datos['apellido'].", ".$datos['nombres'] ?>
                                        </a>
                                    </td>
                                    <td><b style='color:red'><?php echo $datos['dias_mora'] ?></b></td>
                                    <td><b style='color:red'><?php echo $datos['dias_mora_original'] ?></b></td>
                                    <td><?php echo $datos['fecha_ortogacion']->format('d/m/Y') ?></td>
                                    <td><?php echo $datos['monto_financiado'] ?></td>
<!--                                    <td style="text-align: left;"><?php echo $datos['direccion_particular'] ?></td>
                                    <td><?php echo $datos['localidad_particular'] ?></td>
                                    <td style="text-align: left;"><?php echo $datos['direccion_laboral'] ?></td>
                                    <td style="text-align: left;"><?php echo $datos['localidad_laboral'] ?></td>-->
                                    <td style="width:90px;" class="noPrint">
                                        <input type="checkbox" id="cliente_check_<?php echo $i; ?>" name="clientes[]" value="<?php echo $clienteId; ?>" class="cliente_checkbox">
                                    </td>
                                    <td style="width:90px;" class="noPrint">
                                <?php if (!empty($garanteId)) { ?>
                                            <input type="checkbox" id="garante_check_<?php echo $i; ?>" name="garantes[]" value="<?php echo $garanteId; ?>" class="garante_checkbox">
                        <?php } ?>

                                    </td>
                                </tr>
                    <?php $i++;
    } ?>
<?php } else { ?>
                            <tr>
                                <td colspan="5">Sin Resultados</td>
                            </tr>
<?php } ?>
                    </tbody>
                </table>
                <button type="submit" class="btn btn-inverse pull-right"><i class="icon-envelope icon-white "></i> Generar Cartas</button>
            </form>
        </div>
    </div>
</div>


<script>
    
    $(document).ready(function() {
        
        $("#tabla_laborales").chromatable({
            width: "100%",  
            height: "350px",
            scrolling: "yes"
        });
        
    });
    
    function MarcarCheckbox(id, div) {
        // $("." + div + " :checkbox").attr('checked', $('#' + id).is(':checked'));
    
        $("input[type=checkbox]").each(function() { 
        
            if(id=='clientes_check'){
                if($(this).attr('class')=='cliente_checkbox'){
                    if($("#clientes_check").is(":checked")){
                         $(this).attr("checked","checked");
                    }else{
                        $(this).removeAttr("checked");
                       
                    }
                } 
            }else{
                if($(this).attr('class')=='garante_checkbox'){
                    if($("#garantes_check").is(":checked")){
                        $(this).attr("checked","checked");
                    }else{
                        $(this).removeAttr("checked");
                        
                    }
                }   
            }
       
         
        }); 
    }
</script>

<script type="text/javascript">
    //Simple wrapper to pass a jQuery object to your new window
    function PrintElement(elem){
        Popup($(elem).html());
    }

    //Creates a new window and populates it with your content
    function Popup(data) {
        //Create your new window
        var w = window.open('', 'Cartas Laborales <?php echo $this->desde ?> - <?php echo $this->hasta ?>', 'height=600,width=800');
        w.document.write('<html><head><title>Cartas Laborales <?php echo $this->desde ?> - <?php echo $this->hasta ?></title>');
        //Include your stylesheet (optional)
        w.document.write('<link rel="stylesheet" href="<?php echo $this->baseUrl("bootstrap/css/bootstrap.css") ?>" type="text/css" />');
        w.document.write('</head><body>');
        w.document.write('<h2>Cartas Laborales <?php echo $this->desde ?> - <?php echo $this->hasta ?></h2>');
        //Write your content
        w.document.write("<table class='table'>"+data+"</table>");
        w.document.write("<hr>");
        w.document.write($("#totales_ventas").html());
        w.document.write('</body></html>');
        w.print();
        w.close();

        return true;
    }
</script>